package com.opengate.demo.api.config;

import com.opengate.base.threadpool.BaseThreadPoolExecutor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executor;

/**
 * @author 曳戈泰尔
 * @version 1.0
 * @description 自定义线程池
 *     <p>使用注入 @Autowired private Executor threadPoolExecutor;
 * @date 2023/3/14 6:32 PM
 */
@Configuration
public class ThreadPoolExecutorConfig {

    @Value("${thread.pool.core-pool-size}")
    private Integer corePoolSize;

    @Value("${thread.pool.max-pool-size}")
    private Integer maxPoolSize;

    /** 注入Base模块的线程池，传入初始化参数 */
    @Bean(name = "threadPoolExecutor")
    public Executor baseThreadPoolExecutor() {

        return new BaseThreadPoolExecutor(corePoolSize, maxPoolSize).threadPoolExecutor();
    }
}
